﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BVision
{
    public partial class DlgMain : Form
    {
        public DlgMain()
        {
            InitializeComponent();
            Create = false;
        }

        private bool create = false;
        public bool Create
        {
            get
            {
                return create;
            }
            set
            {
                create = value;
                this.label3.Visible = value;
                this.txtPassCfm.Visible = value;
            }
        }
        public string Pass
        {
            get
            {
                return this.txtPass.Text.Trim();
            }
        }
        public string Path
        {
            get
            {
                return this.txtPos.Text.Trim();
            }
        }

        public string User
        {
            get
            {
                return this.txtUser.Text.Trim();
            }
        }

        private void btClean_Click(object sender, EventArgs e)
        {
            foreach (var item in this.groupBox1.Controls)
            {
                if (item.GetType() == typeof(TextBox))
                {
                    ((TextBox)item).Clear();
                }
            }
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {

            FileDialog dialog = getDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.txtPos.Text = dialog.FileName;
            }

        }

        private FileDialog getDialog()
        {
            FileDialog dialog = null;
            if (Create)
            {
                dialog = new SaveFileDialog();
            }
            else
            {
                dialog = new OpenFileDialog();
            }

            dialog.CheckFileExists = false;
            dialog.Filter = "BVision Index File|*.bn|All File|*.*";
            return dialog;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            bool pre = true;
            if (Create)
            {
                pre = this.txtPass.Text.Trim().Equals(txtPassCfm.Text.Trim());

            }
            if (this.txtUser.Text.Trim().Length == 0
                || this.txtPass.Text.Trim().Length == 0
                ||!pre
                || this.txtPos.Text.Trim().Length == 0)
            {
                MessageBox.Show("check your data including password.", "DO NOT CHALLENGE ME:");
            }
            else
            {
                this.DialogResult = DialogResult.OK;
            }

        }
    }
}
